package com.demo.Controller;

import com.demo.entity.Course;
import com.demo.Repository.CourseRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courses")
public class CourseController {

    @Autowired
    private CourseRepository courseRepository;

    @GetMapping("/listAll")
    public List<Course> listAll() {
        return (List<Course>) courseRepository.findAll();
    }

    @GetMapping("/getById/{courseId}")
    public Course getById(@PathVariable Long courseId) {
        return courseRepository.findById(courseId).orElse(null);
    }

    @PostMapping("/add")
    public Course add(@RequestBody Course course) {
        return courseRepository.save(course);
    }
}
//孙伟景22090201135